home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / opt0.4.lcm / bin / hsfconfig < prev    next >
Encoding:
Text File  |  2004-02-26  |  47.0 KB  |  1,973 lines

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2003 Linuxant inc.
  4. #
  5. # NOTE: The use and distribution of this software is governed by the terms in
  6. # the file LICENSE, which is included in the package. You must read this and
  7. # agree to these terms before using or distributing this software.
  8. #
  9. # This script handles all aspects of installing and configuring the
  10. # Conexant HSF softmodem driver under Linux.
  11. #
  12. # It tries to be as distribution-neutral as possible.
  13.  
  14. ask_yesno()
  15. {
  16.     $automode && return $2
  17.  
  18.     while true; do
  19.         echo -n "$1"
  20.         read answer
  21.         case "${answer}" in
  22.         [yY] | [yY][eE][sS])
  23.             return 0
  24.             ;;
  25.         [nN] | [nN][oO])
  26.             return 1
  27.             ;;
  28.         "")
  29.             return $2
  30.             ;;
  31.         *)
  32.             echo "Enter 'yes' or 'no'"
  33.             ;;
  34.         esac
  35.     done
  36. }
  37.  
  38. get_region_list()
  39. {
  40.     (cd ${cnxtnvmdir}/${parm_hwprofile[${unit}]}/Region/ && grep '^' ????_NAME) | \
  41.         sed -e 's/ /_/g' -e 's/^\(....\)_NAME:"\(.*\)"/\2 \1/' | sort
  42. }
  43.  
  44. T35c_to_name()
  45. {
  46.     sed -e 's/"//g' -e 's/ /_/g' \
  47.         < ${cnxtnvmdir}/${parm_hwprofile[${unit}]}/Region/${1}_NAME
  48. }
  49.  
  50. join_comma_wrap_lines()
  51. {
  52.     ${AWK} '{
  53.             if (NR != 1) printf ", "
  54.             printf "%s",$1
  55.         }
  56.         END { print ""}' | fold -s -w78
  57. }
  58.  
  59. ask_region()
  60. {
  61.     get_region_list > /tmp/cnxtconf.sup.$$
  62.  
  63.     while true; do
  64.         if [ -n "${setregion}" ]; then
  65.             answer="${setregion}"
  66.         elif ${automode}; then
  67.             answer="${region}"
  68.         else
  69.             echo ""
  70.             echo -n "Please enter region name for modem unit ${unit} [$region]: "
  71.             read answer
  72.             case "${answer}" in
  73.             "" | *"[     ]"*)
  74.                 answer="${region}"
  75.                 ;;
  76.             *)
  77.                 answer="`echo \"${answer}\" | tr '[a-z ]' '[A-Z_]'`"
  78.                 ;;
  79.             esac
  80.         fi
  81.  
  82.         if grep -i "^${answer}\** " /tmp/cnxtconf.sup.$$ > /tmp/cnxtconf.ncty.$$
  83.         then
  84.             read region regioncode < /tmp/cnxtconf.ncty.$$
  85.             rm -f /tmp/cnxtconf.sup.$$ /tmp/cnxtconf.ncty.$$
  86.             return 0
  87.         else
  88.             echo ""
  89.             echo "ERROR: Region \"${answer}\" is not supported."
  90.  
  91.             if ${automode}; then
  92.                 rm -f /tmp/cnxtconf.sup.$$ /tmp/cnxtconf.ncty.$$
  93.                 return 1
  94.             fi
  95.             setregion=""
  96.             echo ""
  97.             echo "Available countries: "
  98.             echo ""
  99.  
  100.             grep -v '\*' /tmp/cnxtconf.sup.$$ | join_comma_wrap_lines
  101.             echo ""
  102.             grep '\*' /tmp/cnxtconf.sup.$$ | tr -d '\*' | join_comma_wrap_lines
  103.  
  104.         fi
  105.     done
  106. }
  107.  
  108. autodetect_region()
  109. {
  110.     # Try to guess what region we're in, using the timezone settings
  111.  
  112.     localtime_size="`/bin/ls -lL /etc/localtime 2>/dev/null | ${AWK} '{print $5}'`"
  113.  
  114.     if ! [ ${localtime_size} -gt 0 ]; then
  115.         return 1
  116.     fi
  117.  
  118.     zoneinfo_dir=/usr/share/zoneinfo
  119.  
  120.     if [ ! -d ${zoneinfo_dir} -o ! -f ${zoneinfo_dir}/zone.tab ]; then
  121.         return 1
  122.     fi
  123.  
  124.     # The following maps ISO-3166 country codes to T.35 codes
  125.     iso_AR=0007 # ARGENTINA
  126.     iso_AU=0009 # AUSTRALIA
  127.     iso_AT=000A # AUSTRIA
  128.     iso_BH=000C # BAHRAIN
  129.     iso_BD=000D # BANGLADESH
  130.     iso_BE=000F # BELGIUM
  131.     iso_BO=0014 # BOLIVIA
  132.     iso_BR=0016 # BRAZIL
  133.     iso_BN=001A # BRUNEI
  134.     iso_BG=001B # BULGARIA
  135.     iso_CA=0020 # CANADA
  136.     iso_CL=0025 # CHILE
  137.     iso_CN=0026 # CHINA
  138.     iso_CO=0027 # COLOMBIA
  139.     iso_CR=002B # COSTA_RICA
  140.     iso_HR=00FA # CROATIA
  141.     iso_CY=002D # CYPRUS
  142.     iso_CZ=002E # CZECH
  143.     iso_DK=0031 # DENMARK
  144.     iso_DO=0033 # DOMINICAN_REPUBLIC
  145.     iso_EC=0035 # ECUADOR
  146.     iso_EG=0036 # EGYPT
  147.     iso_SV=0037 # EL_SALVADOR
  148.     iso_FI=003C # FINLAND
  149.     iso_FR=003D # FRANCE
  150.     iso_DE=0004 # GERMANY
  151.     iso_GR=0046 # GREECE
  152.     iso_GT=0049 # GUATEMALA
  153.     iso_HT=004E # HAITI
  154.     iso_HN=004F # HONDURAS
  155.     iso_HK=0050 # HONG_KONG
  156.     iso_HU=0051 # HUNGARY
  157.     iso_IS=0052 # ICELAND
  158.     iso_IN=0053 # INDIA
  159.     iso_ID=0054 # INDONESIA
  160.     iso_IE=0057 # IRELAND
  161.     iso_IL=0058 # ISRAEL
  162.     iso_IT=0059 # ITALY
  163.     iso_JP=0000 # JAPAN
  164.     iso_KR=0061 # KOREA
  165.     iso_KW=0062 # KUWAIT
  166.     iso_LA=0063 # LAOS
  167.     iso_LV=00F8 # LATVIA
  168.     iso_LI=0068 # LIECHTENSTEIN
  169.     iso_LU=0069 # LUXEMBOURG
  170.     iso_MO=006A # MACAO
  171.     iso_MY=006C # MALAYSIA
  172.     iso_MT=0070 # MALTA
  173.     iso_MX=0073 # MEXICO
  174.     iso_MN=001C # MYANMAR
  175.     iso_NL=007B # NETHERLANDS
  176.     iso_NZ=007E # NEW_ZEALAND
  177.     iso_NO=0082 # NORWAY
  178.     iso_PK=0084 # PAKISTAN
  179.     iso_PA=0085 # PANAMA
  180.     iso_PY=0087 # PARAGUAY
  181.     iso_PE=0088 # PERU
  182.     iso_PH=0089 # PHILIPPINES
  183.     iso_PL=008A # POLAND
  184.     iso_PT=008B # PORTUGAL
  185.     iso_PR=008C # PUERTO_RICO
  186.     iso_RO=008E # ROMANIA
  187.     iso_RU=00B8 # RUSSIA
  188.     iso_SA=0098 # SAUDI_ARABIA
  189.     iso_SG=009C # SINGAPORE
  190.     iso_SK=00FB # SLOVAKIA
  191.     iso_SI=00FC # SLOVENIA
  192.     iso_ZA=009F # SOUTH_AFRICA
  193.     iso_ES=00A0 # SPAIN
  194.     iso_LK=00A1 # SRI_LANKA
  195.     iso_SE=00A5 # SWEDEN
  196.     iso_CH=00A6 # SWITZERLAND
  197.     iso_TW=00FE # TAIWAN
  198.     iso_TH=00A9 # THAILAND
  199.     iso_TR=00AE # TURKEY
  200.     iso_GB=00B4 # UK
  201.     iso_UA=00B2 # UKRAINE
  202.     iso_AE=00B3 # UNITED_ARAB_EMIRATES
  203.     iso_UY=00B7 # URUGUAY
  204.     iso_US=00B5 # USA
  205.     iso_VE=00BB # VENEZUELA
  206.     iso_VN=00BC # VIETNAM
  207.  
  208.     (
  209.         cd ${zoneinfo_dir} 2>/dev/null || return 1
  210.         find . -type f -size "${localtime_size}"c -print | sed 's@^\./@@' | \
  211.             while read file; do
  212.                 cmp -s /etc/localtime $file || continue
  213. # in the egrep and sed regular expressions below, it is very important to
  214. # have tabs, not spaces
  215.                 egrep "    $file(    .*|\$)" ${zoneinfo_dir}/zone.tab
  216.             done | sed -n '/^[^#]/s/    .*//p' | sort | uniq | \
  217.                 while read code; do
  218.                     eval "echo \${iso_${code}}"
  219.                 done | sort | uniq
  220.         return 0
  221.     )
  222. }
  223.  
  224. configure_region()
  225. {
  226.     region="${setregion}"
  227.     if [ -z "${region}" -a -n "${parm_regionName[${unit}]}" ]; then
  228.         region="${parm_regionName[${unit}]}"
  229.     fi
  230.  
  231.     if [ -z "${region}" -o "${region}" = "AUTO" ]; then
  232.         if [ -z "${autoregion}" ]; then
  233.             regiont35="`autodetect_region | head -1`"
  234.             echo ""
  235.             if [ -z "${regiont35}" ]; then
  236.                 echo "Unable to determine region, defaulting to \"USA\""
  237.                 autoregion=USA
  238.             else
  239.                 autoregion="`T35c_to_name \"${regiont35}\"`"
  240.                 echo "Automatically guessed region (using timezone): \"${autoregion}\""
  241.             fi
  242.         fi
  243.         region="${autoregion}"
  244.         if [ "${setregion}" = "AUTO" ]; then
  245.             setregion="${autoregion}"
  246.         fi
  247.     fi
  248.  
  249.     ask_region || return 1
  250.  
  251.     parm_regionName[${unit}]="${region}"
  252.     parm_regionT35c[${unit}]="${regioncode}"
  253.  
  254.     if ! hsfstop >/dev/null 2>&1; then
  255.         echo ""
  256.         echo "Unable to unload driver to configure region; modem in use?"
  257.         echo "try configuring it manually with \"AT+GCI=${parm_regionT35c[${unit}]}\""
  258.     fi
  259.     sleep 1
  260.  
  261.     echo ""
  262.     echo "Setting region for modem unit ${unit}: \"${parm_regionName[${unit}]}\""
  263.     touch ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/.region_set
  264.     echo "${parm_regionT35c[${unit}]}" > ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/COUNTRY_CODE
  265.     res=$?
  266.  
  267.     return ${res}
  268. }
  269.  
  270. # Convert a key from display to internal format
  271. # The md5sum is used for input verification.
  272. disptokey()
  273. {
  274.     k="`echo \"$1\" | tr '[a-z]' '[A-Z]' | sed 's/FREE/00000000/' | tr -d -c '[0-9A-F\012]'`"
  275.     case $k in
  276.     00000000)
  277.         echo "$k"
  278.         ;;
  279.     ????????????)
  280.         key="`echo \"$k\" | cut -c1-8`"
  281.         if [ "`echo \"${key}\" | md5sum | cut -c1-4 | tr '[a-f]' '[A-F]'`" = "`echo \"$k\" | cut -c9-12`" ]; then
  282.             echo "${key}"
  283.         else
  284.             echo "checksum error"
  285.         fi
  286.         ;;
  287.     *)
  288.         echo "format error"
  289.         ;;
  290.     esac
  291. }
  292.  
  293. # Convert a key from internal to display format
  294. # The md5sum is generated for input verification.
  295. keytodisp()
  296. {
  297.     key="$1"
  298.  
  299.     if [ "${key}" = "00000000" ]; then
  300.         echo FREE
  301.         return 0
  302.     fi
  303.  
  304.     sum="`echo \"${key}\" | md5sum | cut -c1-4 | tr '[a-f]' '[A-F]'`"
  305.  
  306.     echo "${key}${sum}" | sed -e 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)$/\1-\2-\3-\4-\5-\6/'
  307. }
  308.  
  309. ask_license()
  310. {
  311.     while true; do
  312.         if [ -n "${setlicense}" ]; then
  313.             answer="`disptokey \"${setlicense}\"`"
  314.         elif ${automode}; then
  315.             answer="${license}"
  316.         else
  317.             echo ""
  318.  
  319.             echo "License keys can be obtained from http://www.linuxant.com/"
  320.             echo "Without one, the modem operates in FREE mode (max 14.4Kbps data only, no fax)"
  321.             echo ""
  322.             echo "The registration ID for modem unit ${unit} is: ${parm_hwid[${unit}]}"
  323.             echo ""
  324.             echo -n "Please enter license key [`keytodisp \"$license\"`]: "
  325.             read answer
  326.             case "${answer}" in
  327.             "" | *"[     ]"*)
  328.                 answer="${license}"
  329.                 ;;
  330.             *)
  331.                 answer="`disptokey \"${answer}\"`"
  332.                 ;;
  333.             esac
  334.         fi
  335.  
  336.         case "${answer}" in
  337.         [0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F])
  338.             license="${answer}"
  339.             return 0
  340.             ;;
  341.         *)
  342.             echo ""
  343.             echo "ERROR: Invalid license key: \"${answer}\"."
  344.             if ${automode}; then
  345.                 return 1
  346.             fi
  347.             setlicense=""
  348.             ;;
  349.         esac
  350.     done
  351. }
  352.  
  353. ask_licowner()
  354. {
  355.     while true; do
  356.         if [ -n "${setlicowner}" ]; then
  357.             answer="${setlicowner}"
  358.         elif ${automode}; then
  359.             if [ -z "${licowner}" ]; then
  360.                 return 1
  361.             fi
  362.             answer="${licowner}"
  363.         else
  364.             echo ""
  365.             echo "Note: we respect user privacy. Email addresses are not communicated"
  366.             echo "nor used for any purpose other than to manage licenses!"
  367.             echo ""
  368.  
  369.             echo -n "Please enter your email address [$licowner]: "
  370.             read answer
  371.             case "${answer}" in
  372.             "" | *"[     ]"*)
  373.                 answer="${licowner}"
  374.                 ;;
  375.             *)
  376.                 answer="`echo \"${answer}\" | tr '[A-Z]' '[a-z]' | tr -d '[     <>\012]'`"
  377.                 ;;
  378.             esac
  379.         fi
  380.  
  381.         case "${answer}" in
  382.         ?*@?*.?*)
  383.             licowner="${answer}"
  384.             return 0
  385.             ;;
  386.         *)
  387.             if ! ${automode} || [ "${answer}" != "unknown" ]; then
  388.                 echo ""
  389.                 echo "ERROR: Invalid email address format: \"${answer}\"."
  390.             fi
  391.             if ${automode}; then
  392.                 return 1
  393.             fi
  394.             setlicowner=""
  395.             ;;
  396.         esac
  397.     done
  398. }
  399.  
  400. needfullversion() {
  401.     echo ""
  402.     echo "This is the free version of the driver, limited to 14.4Kbps data only."
  403.     echo "For 56K modem and FAX functionality, please upgrade to the full version"
  404.     echo "available from http://www.linuxant.com/"
  405. }
  406.  
  407. configure_license()
  408. {
  409.     if ${isfreeversion}; then
  410.         needfullversion
  411.         return 1
  412.     fi
  413.  
  414.     licowner="${setlicowner}"
  415.     if [ -z "${licowner}" -a -n "${parm_licowner[${unit}]}" ]; then
  416.         licowner="${parm_licowner[${unit}]}"
  417.         if [ "${licowner}" = "unknown" ]; then
  418.             licowner="${lastowner}"
  419.         fi
  420.     fi
  421.  
  422.     case "${setlicense}" in
  423.     ?*/?*)
  424.         setlicowner="`echo \"${setlicense}\" | ${AWK} -F/ '{print $1}'`"
  425.         setlicense="`echo \"${setlicense}\" | ${AWK} -F/ '{print $2}'`"
  426.         ;;
  427.     *)
  428.         ;;
  429.     esac
  430.  
  431.     if [ -z "${setlicense}" ]; then
  432.         if [ -n "${parm_lickey[${unit}]}" ]; then
  433.             license="${parm_lickey[${unit}]}"
  434.         else
  435.             license=""
  436.         fi
  437.     else
  438.         license="`disptokey \"${setlicense}\"`"
  439.     fi
  440.  
  441.     ask_licowner || return 1
  442.     parm_licowner[${unit}]="${licowner}"
  443.  
  444.     ask_license || return 1
  445.     parm_lickey[${unit}]="${license}"
  446.  
  447.     if ! hsfstop >/dev/null 2>&1; then
  448.         echo ""
  449.         echo "Unable to unload driver to configure license; modem in use?"
  450.         echo "\"License status\" information might not be up to date."
  451.     fi
  452.     sleep 1
  453.  
  454.     echo ""
  455.     echo "Setting license for modem unit ${unit}: \"${parm_licowner[${unit}]}/`keytodisp \"${parm_lickey[${unit}]}\"`\""
  456.     echo "\"${parm_licowner[${unit}]}\"" > ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_OWNER
  457.     [ -n "${parm_licowner[${unit}]}" -a "${parm_licowner[${unit}]}" != "unknown" ] && lastowner="${parm_licowner[${unit}]}"
  458.     echo "${parm_lickey[${unit}]}" > ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_KEY
  459.     rereadparms=true
  460.     res=$?
  461.  
  462.     return ${res}
  463. }
  464.  
  465. get_hwprofile_list()
  466. {
  467.     echo "auto"
  468.     (cd ${cnxtnvmdir} && find . -follow -type d -maxdepth 1 -print) | \
  469.         egrep -v '^\.(\/dynamic)?$' | sed 's@^\./@@' | sort
  470. }
  471.  
  472. ask_hwprofile()
  473. {
  474.     get_hwprofile_list > /tmp/cnxtconf.sup.$$
  475.  
  476.     while true; do
  477.         if [ -n "${sethwprofile}" ]; then
  478.             answer="${sethwprofile}"
  479.         elif ${automode}; then
  480.             answer="${hwprofile}"
  481.         else
  482.             echo ""
  483.             echo "Available hardware profiles: "
  484.             echo ""
  485.  
  486.             ${AWK} '{
  487.                     if (NR != 1) printf ", "
  488.                     if (NR % 5 == 0) print ""
  489.                     printf "%s",$1
  490.                 }
  491.                 END { print ""}' </tmp/cnxtconf.sup.$$
  492.  
  493.             echo ""
  494.             echo "WARNING: choosing an incorrect profile may make the modem unusable"
  495.             echo "or cause system crashes. Use with extreme care!"
  496.             echo ""
  497.             echo -n "Please enter hardware profile name for modem unit ${unit} [$hwprofile]: "
  498.             read answer
  499.             case "${answer}" in
  500.             "" | *"[     ]"*)
  501.                 answer="${hwprofile}"
  502.                 ;;
  503.             *)
  504.                 ;;
  505.             esac
  506.         fi
  507.  
  508.         if grep -q -i "^${answer}$" /tmp/cnxtconf.sup.$$
  509.         then
  510.             hwprofile="${answer}"
  511.             rm -f /tmp/cnxtconf.sup.$$
  512.             return 0
  513.         else
  514.             echo ""
  515.             echo "ERROR: \"${answer}\" is not available."
  516.  
  517.             if ${automode}; then
  518.                 rm -f /tmp/cnxtconf.sup.$$
  519.                 return 1
  520.             fi
  521.             sethwprofile=""
  522.         fi
  523.     done
  524. }
  525.  
  526. configure_hwprofile()
  527. {
  528.     hwprofile="${sethwprofile}"
  529.     if [ -z "${hwprofile}" -a -n "${parm_hwprofile[${unit}]}" ]; then
  530.         if [ -s ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/HARDWARE_PROFILE ]; then
  531.             hwprofile="${parm_hwprofile[${unit}]}"
  532.         else
  533.             hwprofile="auto"
  534.         fi
  535.     fi
  536.  
  537.     ask_hwprofile || return 1
  538.     parm_hwprofile[${unit}]="${hwprofile}"
  539.  
  540.     if ! hsfstop >/dev/null 2>&1; then
  541.         echo ""
  542.         echo "Unable to unload driver to configure hwprofile; modem in use?"
  543.     fi
  544.     sleep 1
  545.  
  546.     echo ""
  547.     echo "Setting hwprofile for modem unit ${unit}: \"${hwprofile}\""
  548.     if [ "${parm_hwprofile[${unit}]}" = "auto" ]; then
  549.         rm -f ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/HARDWARE_PROFILE
  550.         parm_hwprofile[${unit}]="unknown"
  551.         rereadparms=true
  552.     else
  553.         echo "\"${parm_hwprofile[${unit}]}\"" > ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/HARDWARE_PROFILE
  554.     fi
  555.     res=$?
  556.  
  557.     return ${res}
  558. }
  559.  
  560. use_prebuilt_modules()
  561. {
  562.     rm -f "/lib/modules/${OSKERNVERS}/misc/hsf"*.${KO}
  563.     if [ ! -d "/lib/modules/${OSKERNVERS}/misc" ]; then
  564.         mkdir -p "/lib/modules/${OSKERNVERS}/misc"
  565.     fi
  566.     ln -s "${cnxtlibdir}/modules/binaries/$1/hsf"*.${KO} "/lib/modules/${OSKERNVERS}/misc/"
  567. }
  568.  
  569. files_present()
  570. {
  571.     for f; do
  572.         if [ ! -f "${f}" ]; then
  573.             missing_file="${f}"
  574.             return 1
  575.         fi
  576.     done
  577. }
  578.  
  579. remove_temp_kernel_tree()
  580. {
  581.     if [ -n "${KERNELORG}" ]; then
  582.         rm -rf "${KERNELSRC}"
  583.         KERNELSRC="${KERNELORG}"
  584.         KERNELORG=""
  585.         return 0
  586.     fi
  587.  
  588.     return 1
  589. }
  590.  
  591. create_temp_kernel_tree()
  592. {
  593.     KERNELORG="${KERNELSRC}"
  594.     # get absolute pathname with cd/pwd to ensure that our temp dir
  595.     # is on same filesystem due to use of hardlinks by cp -al
  596.     KERNELSRC="`(cd \"${KERNELORG}\" && /bin/pwd)`-cnxttmp$$"
  597.     rm -rf "${KERNELSRC}"
  598.     if ! cp -al "${KERNELORG}/." "${KERNELSRC}"; then
  599.         remove_temp_kernel_tree
  600.         return 1
  601.     fi
  602.  
  603.     return 0
  604. }
  605.  
  606. kernelrebuild_instructions()
  607. {
  608.         echo ""
  609.         echo "First, ensure that the proper kernel source and compiler packages"
  610.         echo "from your distribution vendor and/or the community are installed."
  611.         echo ""
  612.         echo "The Linux kernel can then be reconfigured by running \"make menuconfig\""
  613.         echo "under the kernel source directory (usually /usr/src/linux)."
  614.         echo ""
  615.         echo "Verify that the proper options for your system are selected."
  616.         echo ""
  617.         echo "Then compile and install your new kernel (for more information about"
  618.         echo "this procedure, see the README file under the kernel source directory),"
  619.         echo "reboot the system using the new kernel, and re-run \"hsfconfig\"."
  620. }
  621.  
  622. check_kernel()
  623. {
  624. #    if [ -n "$OSKERNSMP" ]; then
  625. #        echo 1>&2 ""
  626. #        echo 1>&2 "This driver has not been fully tested on SMP kernels."
  627. #        echo 1>&2 "Please report results to <modem.support@linuxant.com>"
  628. #    fi
  629.  
  630.     case "${OSKERNVERS}" in
  631.     2.2*)
  632.         echo ""
  633.         echo 1>&2 "ERROR: 2.2 kernels are no longer supported by this driver!"
  634.         echo 1>&2 "Please upgrade your Linux distribution or kernel to version 2.4 or 2.6"
  635.         return 1
  636.         ;;
  637.     *)
  638.         ;;
  639.     esac
  640.  
  641.     return 0
  642. }
  643.  
  644. right_version_file()
  645. {
  646.     _versionf="$1"
  647.  
  648.     FILEKERNELVER="`echo UTS_RELEASE | gcc -E -I"${KERNELSRC}/include" -include "${_versionf}" - | grep '^"' | tr -d '"     '`"
  649.  
  650.     [ "${OSKERNVERS}" = "${FILEKERNELVER}" ]
  651. }
  652.  
  653. update_module_dependencies()
  654. {
  655.     depmod -A -e -u >/tmp/cnxtconf.depmod.$$ 2>&1
  656.     res=$?
  657.  
  658.     cat 1>&2 /tmp/cnxtconf.depmod.$$
  659.  
  660.     if [ ${res} -ne 0 ]; then
  661.         # only return error if one of our modules is at cause
  662.         grep -q "hsf" /tmp/cnxtconf.depmod.$$ || res=0
  663.     fi
  664.  
  665.     rm -f /tmp/cnxtconf.depmod.$$
  666.  
  667.     return ${res}
  668. }
  669.  
  670. recompile_modules()
  671. {
  672.     KERNELSRC=/usr/src/linux
  673.     KERNELORG=""
  674.  
  675.     if [ -h /lib/modules/${OSKERNVERS}/build -a ! -d /lib/modules/${OSKERNVERS}/build/. ]; then
  676.         echo ""
  677.         echo "ERROR: /lib/modules/${OSKERNVERS}/build points to a missing directory"
  678.         echo ""
  679.         ls -l /lib/modules/${OSKERNVERS}/build
  680.         echo ""
  681.         if rpm -qf /lib/modules/${OSKERNVERS} >/dev/null 2>&1; then
  682.             echo "Please ensure that the kernel-source RPM package is properly installed."
  683.         else
  684.             echo "Please ensure that the kernel-source is properly installed."
  685.         fi
  686.         return 1
  687.     fi
  688.  
  689.     if [ -d /lib/modules/${OSKERNVERS}/build/include ]; then
  690.         KERNELSRC=/lib/modules/${OSKERNVERS}/build
  691.     elif [ ! -d "${KERNELSRC}" -a -d "/usr/src/kernel-headers-${OSKERNVERS}" ]; then
  692.         # Debian
  693.         KERNELSRC=/usr/src/kernel-headers-${OSKERNVERS}
  694.     elif [ ! -d "${KERNELSRC}" -a -d "/usr/local/src/linux" ]; then
  695.         KERNELSRC=/usr/local/src/linux
  696.     elif [ ! -d "${KERNELSRC}" ]; then
  697.         echo "Please ensure that the kernel-source is properly installed."
  698.         if [ "${OSDISTNAME}" = Debian ]; then
  699.             echo "On Debian, try \"apt-get install kernel-headers-${OSKERNVERS}\""
  700.         fi
  701.     fi
  702.     if ! $automode; then
  703.         echo ""
  704.         echo "Where is the linux source build directory that matches your running kernel?"
  705.         echo -n "[${KERNELSRC}] "
  706.         read answer
  707.         case "${answer}" in
  708.         "")
  709.             ;;
  710.         *)
  711.             KERNELSRC="${answer}"
  712.             ;;
  713.         esac
  714.     fi
  715.  
  716.     if [ -e "${KERNELSRC}/scripts/Makefile.build" ]; then
  717.         use_kbuild=true
  718.     else
  719.         use_kbuild=false
  720.     fi
  721.  
  722.     if ! files_present \
  723.         "${KERNELSRC}/include/linux/autoconf.h" \
  724.         "${KERNELSRC}/include/linux/version.h" ||
  725.         (! ${use_kbuild} && ! files_present "${KERNELSRC}/include/linux/modversions.h"); then
  726.         echo ""
  727.         echo "WARNING: missing file ${missing_file}"
  728.         suspect_tree=true
  729.     elif ! right_version_file "${KERNELSRC}/include/linux/version.h"; then
  730.         echo ""
  731.         echo "WARNING: the kernel version (${FILEKERNELVER}) defined in"
  732.         echo "${KERNELSRC}/include/linux/version.h"
  733.         echo "does not match the currently running kernel (${OSKERNVERS})"
  734.         echo "The cause of this problem is an incorrect kernel source path."
  735.         echo "Please check that ${KERNELSRC} points to the right tree."
  736.         suspect_tree=true
  737.     else
  738.         suspect_tree=false
  739.     fi
  740.  
  741.     if ${suspect_tree}; then
  742.         echo "The cause of this problem is usually a missing or misconfigured"
  743.         echo "kernel source tree (and sometimes an incorrect directory or symbolic link)."
  744.         # SuSE has copies of autoconf.h and version.h available under /boot
  745.         if [ -d "${KERNELSRC}/include/linux" -a -f /boot/vmlinuz.autoconf.h -a -f /boot/vmlinuz.version.h ] && right_version_file /boot/vmlinuz.version.h && [ -f "${KERNELSRC}/include/linux/modversions.h" ]; then
  746.             echo ""
  747.             echo "However, proper /boot/vmlinuz.{autoconf.h,version.h} were found."
  748.             if ask_yesno "Would you like to try using them (in a temporary kernel tree)? [yes] " 0; then
  749.                 if ! create_temp_kernel_tree; then
  750.                     echo ""
  751.                     echo "Unable to create temporary kernel tree"
  752.                     kernelrebuild_instructions
  753.                     return 1
  754.                 fi
  755.                 rm -f "${KERNELSRC}/include/linux/.config" \
  756.                         "${KERNELSRC}/include/linux/autoconf.h" \
  757.                         "${KERNELSRC}/include/linux/version.h"
  758.                 if ! cp -p /boot/vmlinuz.autoconf.h "${KERNELSRC}/include/linux/autoconf.h" || \
  759.                     ! cp -p /boot/vmlinuz.version.h "${KERNELSRC}/include/linux/version.h"; then
  760.                     echo ""
  761.                     echo "Unable to copy files to temporary kernel tree"
  762.                     remove_temp_kernel_tree
  763.                     kernelrebuild_instructions
  764.                     return 1
  765.                 fi
  766.  
  767.                 # we don't really need .config but it can't hurt if available
  768.                 if [ -f /boot/vmlinuz.config ]; then
  769.                     cp -p /boot/vmlinuz.config "${KERNELSRC}/include/linux/.config"
  770.                 fi
  771.             fi
  772.         fi
  773.     fi
  774.  
  775.     # are we ok now?
  776.     if [ ! -f "${KERNELSRC}/include/linux/version.h" \
  777.             -o ! -f "${KERNELSRC}/include/linux/autoconf.h" ] || \
  778.             [ ! -f "${KERNELSRC}/include/linux/modversions.h" ] && ! ${use_kbuild}; then
  779.         remove_temp_kernel_tree
  780.         kernelrebuild_instructions
  781.         return 1
  782.     fi
  783.  
  784.     buildlogf=/tmp/hsfconfig-buildlog.txt
  785.  
  786.     # set FILEKERNELVER if it isn't already
  787.     [ -n "${FILEKERNELVER}" ] || right_version_file "${KERNELSRC}/include/linux/version.h"
  788.  
  789.     echo ""
  790.     echo "Building modules for kernel ${FILEKERNELVER}, using source directory"
  791.     echo "${KERNELSRC}. Please wait.."
  792.  
  793.     (cd ${cnxtlibdir}/modules && make "KERNELSRC=${KERNELSRC}" clean minstall) > ${buildlogf} 2>&1
  794.     res=$?
  795.  
  796.     (cd ${cnxtlibdir}/modules && make "KERNELSRC=${KERNELSRC}" clean) >/dev/null 2>&1
  797.  
  798.     remove_temp_kernel_tree
  799.  
  800.     if [ $res -eq 0 ]; then
  801.         rm -f ${buildlogf}
  802.         return 0
  803.     else
  804.         echo ""
  805.         echo "ERROR: Module build failed!"
  806.         echo "Please examine the log file \"${buildlogf}\" to determine why."
  807.         return 1
  808.     fi
  809. }
  810.  
  811. dcp_supported()
  812. {
  813.     [ "hsf" = "hsf" ]
  814. }
  815.  
  816. diag_supported()
  817. {
  818.     true
  819. }
  820.  
  821. old_scr_supported()
  822. {
  823.     modinfo -p hsfosspec 2>/dev/null | grep -q scrmajor
  824. }
  825.  
  826. modules_exist()
  827. {
  828.     files_present "/lib/modules/${OSKERNVERS}/misc/hsf"*.${KO}
  829. }
  830.  
  831. remove_kernel_modules()
  832. {
  833.     if modules_exist; then
  834.         echo ""
  835.         echo "Removing hsf driver from /lib/modules/${OSKERNVERS}/misc/"
  836.         rm -f "/lib/modules/${OSKERNVERS}/misc/hsf"*.${KO}
  837.     fi
  838.     return 0
  839. }
  840.  
  841. binary_modules_avail()
  842. {
  843.     [ -d "${cnxtlibdir}/modules/binaries/$1" ]
  844. }
  845.  
  846. configure_kernel()
  847. {
  848.     check_kernel || return $?
  849.  
  850.     if modules_exist; then
  851.         echo ""
  852.         echo "Warning: existing driver modules found under:"
  853.         echo "    /lib/modules/${OSKERNVERS}/misc/"
  854.         if ask_yesno "Would you like to keep using them? [no] " 1; then
  855.             return 0
  856.         fi
  857.     fi
  858.  
  859.     chosen_binary_modules=""
  860.     if binary_modules_avail "${OSKERNTYPE}/${OSDISTIDNT}/${OSKERNNAME}-${OSKERNVERS}${OSKERNSMP}"; then
  861.         chosen_binary_modules="${OSKERNTYPE}/${OSDISTIDNT}/${OSKERNNAME}-${OSKERNVERS}${OSKERNSMP}"
  862.     fi
  863.  
  864.     if [ -n "${chosen_binary_modules}" ]; then
  865.         echo ""
  866.         echo "Pre-built driver modules that seem compatible with your system were found under"
  867.         echo "${cnxtlibdir}/modules/binaries/${chosen_binary_modules}."
  868.  
  869.         if ask_yesno "Would you like to use them? [yes] " 0; then
  870.             if use_prebuilt_modules "${chosen_binary_modules}"; then
  871.                 hsfstop # unload any old modules loaded
  872.                 update_module_dependencies || return $?
  873.                 return 0
  874.             fi
  875.         fi
  876.     else
  877.         echo ""
  878.         echo "No pre-built modules for: ${OSDISTNAME}-${OSDISTVERS} ${OSKERNNAME}-${OSKERNVERS} ${OSKERNTYPE}${OSKERNSMP}"
  879.     fi
  880.  
  881.     if [ -f ${cnxtlibdir}/modules/Makefile ]; then
  882.         echo ""
  883.         echo "Trying to automatically build the driver modules.."
  884.         echo "(this requires a C compiler and proper kernel sources to be installed)"
  885.  
  886.         if recompile_modules; then
  887.                 hsfstop # unload any old modules loaded
  888.                 update_module_dependencies || return $?
  889.                 echo "done."
  890.                 return 0
  891.         fi
  892.     else
  893.         echo ""
  894.         echo "Please obtain the appropriate variant of this package for your system"
  895.         echo "or try the generic RPM or tar version."
  896.     fi
  897.  
  898.     return 1
  899. }
  900.  
  901. choose_major()
  902. {
  903.     device=$1
  904.     shift
  905.  
  906.     first=240
  907.     max=250
  908.  
  909.     major=${first}
  910.  
  911.     while [ ${major} -ne ${max} ]; do
  912.         excluded=false
  913.         for exclude in $*; do
  914.             if [ ${major} -eq ${exclude} ]; then
  915.                 excluded=true
  916.                 break
  917.             fi
  918.         done
  919.  
  920.         if ! ${excluded} && \
  921.             ! grep -q "^ *${major} " /proc/devices && \
  922.             ! sed -e 's/#.*//g' \
  923.                 -e '/hsfserial/d' \
  924.                 -e '/ttySHSF$/d' \
  925.                 -e '/hsfosspec/d' \
  926.                 -e '/hsfdiag/d' \
  927.                 -e '/hsfscr/d' \
  928.                 ${modulesconf} | grep -q "^alias[     ][     ]*char-major-${major}"
  929.             then
  930.                 break
  931.         fi
  932.  
  933.         major="`expr ${major} + 1`"
  934.     done
  935.  
  936.     if [ ${major} -ne ${max} ]; then
  937.         echo ${major}
  938.         return 0
  939.     else
  940.         echo 1>&2 "$0: Cannot find major device number for ${device} in range ${first}-${max}"
  941.         return 1
  942.     fi
  943. }
  944.  
  945. devfsd_running()
  946. {
  947.     ps -e | grep -q 'devfsd$'
  948. }
  949.  
  950. modulesconf_filter_mine()
  951. {
  952.     sed \
  953.     -e '/^alias.*hsfserial/d' \
  954.     -e '/^alias.*ttySHSF$/d' \
  955.     -e '/^options.*hsfserial/d' \
  956.     -e '/^probeall.*ttySHSF[     ]/d' \
  957.     -e '/^probeall.*hsfserial/d' \
  958.     -e '/^below[     ]*hsfhw/d' \
  959.     -e '/^alias.*hsfosspec/d' \
  960.     -e '/^options.*hsfosspec/d' \
  961.     -e '/^alias.*hsfdiag/d' \
  962.     -e '/^alias.*hsfscr/d' \
  963.     -e '/^options.*hsfscr/d'
  964. }
  965.  
  966. modprobeconf_filter_mine()
  967. {
  968.     sed \
  969.     -e '/^alias.*hsfserial/d' \
  970.     -e '/^alias.*ttySHSF$/d' \
  971.     -e '/^options.*hsfserial/d' \
  972.     -e '/^install.*ttySHSF[     ]/d' \
  973.     -e '/^install[     ]*hsfserial/d' \
  974.     -e '/^remove[     ]*hsfserial/d' \
  975.     -e '/^install[     ]*hsfosspec/d' \
  976.     -e '/^remove[     ]*hsfosspec/d' \
  977.     -e '/^install[     ]*hsfhw/d' \
  978.     -e '/^remove[     ]*hsfhw/d' \
  979.     -e '/^alias.*hsfosspec/d' \
  980.     -e '/^options.*hsfosspec/d' \
  981.     -e '/^alias.*hsfdiag/d' \
  982.     -e '/^alias.*hsfscr/d' \
  983.     -e '/^options.*hsfscr/d'
  984. }
  985.  
  986. unconfigure_serial()
  987. {
  988.     if [ -f /etc/modutils/hsf ]; then
  989.         rm -f /etc/modutils/hsf
  990.         update-modules
  991.     elif [ -f /etc/modules.d/hsf ]; then
  992.         rm -f /etc/modules.d/hsf
  993.         update-modules
  994.     else
  995.         if modulesconf_filter_mine < ${modulesconf} > ${modulesconf}.$$; then
  996.             cp ${modulesconf}.$$ ${modulesconf}
  997.         fi
  998.  
  999.         rm -f ${modulesconf}.$$
  1000.     fi
  1001.  
  1002.     if [ -n "${modprobeconf}" -a -f "${modprobeconf}" ]; then
  1003.         if modprobeconf_filter_mine < ${modprobeconf} > ${modprobeconf}.$$; then
  1004.             cp ${modprobeconf}.$$ ${modprobeconf}
  1005.         fi
  1006.  
  1007.         rm -f ${modprobeconf}.$$
  1008.     fi
  1009.  
  1010.     if [ -f /etc/devfs/conf.d/hsf.conf ]; then
  1011.         rm -f /etc/devfs/conf.d/hsf.conf
  1012.         [ -x /usr/sbin/update-devfsd ] && update-devfsd
  1013.         killall -HUP devfsd 2>/dev/null
  1014.     else
  1015.         if [ -f /etc/devfsd.conf ]; then
  1016.             if sed -e '/^REGISTER.*ttyS*HSF[0-9]/d' -e '/^LOOKUP.*ttySHSF[0-9]/d' \
  1017.                     < /etc/devfsd.conf > /etc/devfsd.conf.$$; then
  1018.                 cp /etc/devfsd.conf.$$ /etc/devfsd.conf
  1019.             fi
  1020.             rm -f /etc/devfsd.conf.$$
  1021.             killall -HUP devfsd 2>/dev/null
  1022.         fi
  1023.     fi
  1024.  
  1025.     if ! devfsd_running; then
  1026.         rm -f /dev/hsfdcp[0-9]*
  1027.         rm -f /dev/hsfdiag[0-9]* /dev/hsfdiagdmp
  1028.         rm -f /dev/ttySHSF[0-9]*
  1029.         rm -f /dev/cuaHSF[0-9]*
  1030.     fi
  1031.  
  1032.     if [ -h /dev/modem ] && /bin/ls -l /dev/modem 2>/dev/null | ${AWK} '{print $11}' | egrep -q '(ttyS|cua)HSF[0-9][0-9]*'; then
  1033.         rm -f /dev/modem
  1034.     fi
  1035. }
  1036.  
  1037. mod_aliases_and_options()
  1038. {
  1039.     echo "alias /dev/ttySHSF[0-9]* /dev/ttySHSF"
  1040.     echo "alias char-major-${cnxttty_major} /dev/ttySHSF"
  1041.     echo "alias /dev/modem /dev/ttySHSF"
  1042.     if [ "$1" = modulesconf ]; then
  1043.         echo "alias /dev/cuaHSF[0-9]* /dev/ttySHSF"
  1044.         echo "alias char-major-${cnxtcua_major} /dev/ttySHSF"
  1045.         echo "options hsfserial serialmajor=${cnxttty_major} calloutmajor=${cnxtcua_major}"
  1046.     else
  1047.         echo "options hsfserial serialmajor=${cnxttty_major}"
  1048.     fi
  1049.     osspecargs=""
  1050.     if [ -n "${cnxtdcp_major}" ]; then
  1051.         osspecargs="${osspecargs} dcpmajor=${cnxtdcp_major}"
  1052.     fi
  1053.     if [ -n "${cnxtdiag_major}" ]; then
  1054.         echo "alias /dev/hsfdiag hsfosspec"
  1055.         echo "alias /dev/hsfdiag* /dev/hsfdiag"
  1056.         echo "alias char-major-${cnxtdiag_major} /dev/hsfdiag"
  1057.         osspecargs="${osspecargs} diagmajor=${cnxtdiag_major}"
  1058.     fi
  1059.     if [ -n "${cnxtscr_major}" ]; then
  1060.         echo "alias ${scrdevicename} hsfosspec"
  1061.         echo "alias char-major-${cnxtscr_major} hsfosspec"
  1062.         osspecargs="${osspecargs} scrmajor=${cnxtscr_major}"
  1063.     fi
  1064.     if [ -n "${osspecargs}" ]; then
  1065.         echo "options hsfosspec${osspecargs}"
  1066.     fi
  1067. }
  1068.  
  1069. configure_serial()
  1070. {
  1071.     cnxttty_major="`choose_major hsfserial`"
  1072.  
  1073.     if [ -z ${cnxttty_major} ]; then
  1074.         exit 1
  1075.     fi
  1076.  
  1077.     cnxtcua_major="`choose_major hsfserial_callout ${cnxttty_major}`"
  1078.     if [ -z ${cnxtcua_major} ]; then
  1079.         exit 1
  1080.     fi
  1081.  
  1082.     if dcp_supported; then
  1083.         cnxtdcp_major="`choose_major hsfdcp ${cnxttty_major} ${cnxtcua_major}`"
  1084.         if [ -z ${cnxtdcp_major} ]; then
  1085.             exit 1
  1086.         fi
  1087.     else
  1088.         cnxtdcp_major=""
  1089.     fi
  1090.  
  1091.     if diag_supported; then
  1092.         cnxtdiag_major="`choose_major hsfdiag ${cnxttty_major} ${cnxtcua_major} ${cnxtdcp_major}`"
  1093.         if [ -z ${cnxtdiag_major} ]; then
  1094.             exit 1
  1095.         fi
  1096.     else
  1097.         cnxtdiag_major=""
  1098.     fi
  1099.  
  1100.     if old_scr_supported; then
  1101.         scrdevicename=/dev/hsfscr
  1102.  
  1103.         cnxtscr_major="`choose_major hsfscr ${cnxttty_major} ${cnxtcua_major} ${cnxtdcp_major} ${cnxtdiag_major}`"
  1104.         if [ -z ${cnxtscr_major} ]; then
  1105.             exit 1
  1106.         fi
  1107.     fi
  1108.  
  1109.     if [ -d /etc/modutils -a -x /sbin/update-modules ]; then
  1110.         # Debian
  1111.         runupdatemodules=true
  1112.         outmodulesconf=/etc/modutils/hsf
  1113.     elif [ -d /etc/modules.d -a -x /usr/sbin/update-modules ]; then
  1114.         # Gentoo
  1115.         runupdatemodules=true
  1116.         outmodulesconf=/etc/modules.d/hsf
  1117.     else
  1118.         runupdatemodules=false
  1119.         outmodulesconf=/tmp/cnxtmodconf.$$
  1120.     fi
  1121.  
  1122.     (
  1123.         mod_aliases_and_options modulesconf
  1124.         if [ "hsf" = "hsf" ]; then
  1125.             echo "probeall /dev/ttySHSF hsfpcibasic2 hsfmc97ich hsfmc97via hsfmc97ali"
  1126.             echo "probeall hsfserial hsfpcibasic2 hsfmc97ich hsfmc97via hsfmc97ali"
  1127.         fi
  1128.         if [ "hsf" = "hcf" ]; then
  1129.             echo "probeall /dev/ttySHSF hsfhw"
  1130.             echo "probeall hsfserial hsfhw"
  1131.         fi
  1132.  
  1133.         case "${parm_hwinst[${unit}]}" in
  1134.         PCI-4321:*)
  1135.             # RipTide HCF
  1136.             echo "below hsfhw riptidelow"
  1137.             ;;
  1138.         *)
  1139.             ;;
  1140.         esac
  1141.     ) > ${outmodulesconf}
  1142.  
  1143.     if ${runupdatemodules}; then
  1144.         update-modules
  1145.     else
  1146.         if (
  1147.             modulesconf_filter_mine
  1148.             cat ${outmodulesconf}
  1149.         )  < ${modulesconf} > ${modulesconf}.$$; then
  1150.             if ! cp ${modulesconf}.$$ ${modulesconf}; then
  1151.                 rm -f ${modulesconf}.$$ ${outmodulesconf}
  1152.                 exit 1
  1153.             fi
  1154.         fi
  1155.  
  1156.         rm -f ${modulesconf}.$$ ${outmodulesconf}
  1157.     fi
  1158.  
  1159.     if [ -n "${modprobeconf}" ]; then
  1160.         outmodprobeconf=/tmp/cnxtmodconf.$$
  1161.         (
  1162.             mod_aliases_and_options
  1163.             if [ "hsf" = "hsf" ]; then
  1164.                 echo "install /dev/ttySHSF /sbin/modprobe hsfpcibasic2; /sbin/modprobe hsfmc97ich; /sbin/modprobe hsfmc97via; /sbin/modprobe hsfmc97ali; /bin/true"
  1165.             fi
  1166.             if [ "hsf" = "hcf" ]; then
  1167.                 echo "install /dev/ttySHSF /sbin/modprobe hsfhw"
  1168.             fi
  1169.  
  1170.             case "${parm_hwinst[${unit}]}" in
  1171.             PCI-4321:*)
  1172.                 # RipTide HCF
  1173.                 echo "install hsfhw /sbin/modprobe riptidelow; /sbin/modprobe --ignore-install hsfhw"
  1174.                 echo "remove hsfhw /sbin/modprobe -r --ignore-remove hsfhw && /sbin/modprobe -r riptidelow; /bin/true"
  1175.                 ;;
  1176.             *)
  1177.                 ;;
  1178.             esac
  1179.  
  1180.         ) > ${outmodprobeconf}
  1181.  
  1182.         if (
  1183.             modprobeconf_filter_mine
  1184.             cat ${outmodprobeconf}
  1185.         ) < ${modprobeconf} > ${modprobeconf}.$$; then
  1186.             if ! cp ${modprobeconf}.$$ ${modprobeconf}; then
  1187.                 rm -f ${modprobeconf}.$$ ${outmodprobeconf}
  1188.                 exit 1
  1189.             fi
  1190.         fi
  1191.  
  1192.         rm -f ${modprobeconf}.$$ ${outmodprobeconf}
  1193.     fi
  1194.  
  1195.     if [ -d /etc/devfs/conf.d ]; then
  1196.         # we use nice to bypass the stupid check in devfsd (Hi Richard!)
  1197.         # that prevents direct execution of modprobe (in favor of MODLOAD,
  1198.         # which unfortunately doesn't provide a way to specify a module
  1199.         # name other than the device itself and under Mandrake at least,
  1200.         # the ttyS* alias in /etc/modules.devfs overrides our own alias
  1201.         # in modules.conf)
  1202.         echo 'LOOKUP    ^(ttySHSF[0-9]|modem$) EXECUTE nice /sbin/modprobe /dev/ttySHSF
  1203. REGISTER    ^ttySHSF0$ CFUNCTION GLOBAL symlink $devname modem
  1204. UNREGISTER    ^ttySHSF0$ CFUNCTION GLOBAL unlink modem' \
  1205.             > /etc/devfs/conf.d/hsf.conf
  1206.         rm -f /dev/modem
  1207.         [ -x /usr/sbin/update-devfsd ] && update-devfsd
  1208.         killall -HUP devfsd 2>/dev/null
  1209.     else
  1210.         if [ -f /etc/devfsd.conf ]; then
  1211.             if (
  1212.                 sed -e '/REGISTER.*ttyS*HSF[0-9]/d' -e '/^LOOKUP.*ttySHSF[0-9]/d'
  1213.                 echo 'LOOKUP    ^(ttySHSF[0-9]|modem$) EXECUTE nice /sbin/modprobe /dev/ttySHSF
  1214. REGISTER    ^ttySHSF0$ CFUNCTION GLOBAL symlink $devname modem
  1215. UNREGISTER    ^ttySHSF0$ CFUNCTION GLOBAL unlink modem'
  1216.             ) < /etc/devfsd.conf > /etc/devfsd.conf.$$; then
  1217.                 cp /etc/devfsd.conf.$$ /etc/devfsd.conf
  1218.             fi
  1219.             rm -f /etc/devfsd.conf.$$
  1220.             rm -f /dev/modem
  1221.             killall -HUP devfsd 2>/dev/null
  1222.         fi
  1223.     fi
  1224.  
  1225.     ttydevicename=/dev/ttySHSF0
  1226.     cuadevicename=/dev/cuaHSF0
  1227.  
  1228.     if [ -n "${scrdevicename}" ]; then
  1229.         rm -f ${scrdevicename}
  1230.         mknod -m 600 ${scrdevicename} c ${cnxtscr_major} 0 || exit 1
  1231.     fi
  1232.  
  1233.     if ! devfsd_running; then
  1234.  
  1235.         rm -f /dev/hsfdcp[0-9]*
  1236.         rm -f /dev/hsfdiag[0-9]* /dev/hsfdiagdmp
  1237.         rm -f /dev/ttySHSF[0-9]*
  1238.         rm -f /dev/cuaHSF[0-9]*
  1239.  
  1240.         if [ -n "${cnxtdcp_major}" ]; then
  1241.             u=0
  1242.             while [ $u -lt 8 ]; do
  1243.                     mknod -m 666 /dev/hsfdcp${u} c ${cnxtdcp_major} ${u} || exit 1
  1244.                 u=`expr $u + 1`
  1245.             done
  1246.         fi
  1247.  
  1248.         if [ -n "${cnxtdiag_major}" ]; then
  1249.             u=0
  1250.             while [ $u -lt 8 ]; do
  1251.                     mknod -m 666 /dev/hsfdiag${u} c ${cnxtdiag_major} ${u} || exit 1
  1252.                 u=`expr $u + 1`
  1253.             done
  1254.             mknod -m 666 /dev/hsfdiagdmp c ${cnxtdiag_major} 255 || exit 1
  1255.         fi
  1256.  
  1257.         cnxt_minor=64
  1258.  
  1259.         u=0
  1260.         while [ $u -lt 8 ]; do
  1261.                 mknod -m 666 /dev/ttySHSF${u} c ${cnxttty_major} ${cnxt_minor} || exit 1
  1262.             mknod -m 666 /dev/cuaHSF${u} c ${cnxtcua_major} ${cnxt_minor} || exit 1
  1263.             cnxt_minor=`expr $cnxt_minor + 1`
  1264.             u=`expr $u + 1`
  1265.         done
  1266.  
  1267.         if [ -h /dev/modem ] && /bin/ls -l /dev/modem 2>/dev/null | ${AWK} '{print $11}' | egrep -q '(ttyS|cua)HSF[0-9][0-9]*'; then
  1268.             rm -f /dev/modem
  1269.         fi
  1270.  
  1271.         if [ -e /dev/modem ]; then
  1272.             if ! fuser /dev/modem >/dev/null 2>&1; then
  1273.                 rm -f /dev/modem.old
  1274.                 mv /dev/modem /dev/modem.old
  1275.  
  1276.                 echo "WARNING: renamed existing /dev/modem to /dev/modem.old:"
  1277.                 echo ""
  1278.                 /bin/ls -l /dev/modem.old
  1279.             fi
  1280.         fi
  1281.  
  1282.         if [ ! -e /dev/modem ]; then
  1283.             ln -s /dev/ttySHSF0 /dev/modem
  1284.         fi
  1285.     fi
  1286. }
  1287.  
  1288. identify_system()
  1289. {
  1290.     OSDISTNAME=unknown
  1291.     OSDISTIDNT=unknown
  1292.     OSDISTVERS=unknown
  1293.  
  1294.     if [ -f /etc/debian_version ]; then
  1295.         OSDISTNAME=Debian
  1296.         OSDISTIDNT=deb
  1297.         read OSDISTVERS < /etc/debian_version
  1298.     elif [ -f /etc/slackware-version ]; then
  1299.         OSDISTNAME=Slackware
  1300.         OSDISTIDNT=slack
  1301.         OSDISTVERS="`${AWK} '{print $1; exit}' /etc/slackware-version`"
  1302.     elif [ -f /etc/conectiva-release ]; then
  1303.         OSDISTNAME=Conectiva
  1304.         OSDISTIDNT=conectiva
  1305.     elif [ -f /etc/SuSE-release ]; then
  1306.         OSDISTNAME=SuSE
  1307.         OSDISTIDNT=suse
  1308.         OSDISTVERS="`sed -n '/^VERSION/s/^.*=[     ]*//p' < /etc/SuSE-release`"
  1309.     elif [ -f /etc/mandrake-release ]; then
  1310.         OSDISTNAME=Mandrake
  1311.         OSDISTIDNT=mdk
  1312.     #it would be better to use rpm instead of sed but it doesn't work
  1313.     #recursively (due to database locking) when this script is called during
  1314.     #the package's installation
  1315.     #    OSDISTVERS="`rpm -q --queryformat '%{VERSION}\n' mandrake-release | sort -r | head -1`"
  1316.         OSDISTVERS="`sed -n '/release /{s/^.*release  *\([^ ]*\)/\1/;s/ .*//;p;q;}' < /etc/mandrake-release`"
  1317.     #elif [ -f /etc/yellowdog-release ]; then
  1318.     #    OSDISTNAME=YellowDog
  1319.     elif [ -f /etc/redhat-release ]; then
  1320.         OSDISTNAME=RedHat
  1321.         OSDISTIDNT=rh
  1322.         OSDISTVERS="`sed -n '/release /{s/^.*release  *\([^ ]*\)/\1/;s/ .*//;p;q;}' < /etc/redhat-release`"
  1323.     elif [ -d /var/lib/LST ]; then
  1324.         OSDISTNAME=Caldera
  1325.         OSDISTIDNT=caldera
  1326.     fi
  1327.  
  1328.     OSKERNNAME="`uname -s | tr '[A-Z]' '[a-z]'`"
  1329.     OSKERNARCH="`uname -m`"
  1330.     if [ -r /boot/kernel.h ]; then
  1331.         OSKERNTYPE="`sed -n '/^#define[     ]__MODULE_KERNEL_/s/^#define[     ]__MODULE_KERNEL_\([^     ]*\)[     ]*.*/\1/p' </boot/kernel.h`"
  1332.     fi
  1333.     if [ -z "${OSKERNTYPE}" ]; then
  1334.         OSKERNTYPE="${OSKERNARCH}"
  1335.     fi
  1336.     OSKERNVERS="`uname -r`"
  1337.  
  1338.     case "${OSKERNVERS}" in
  1339.     2.[234]*)
  1340.         KO=o
  1341.         ksyms=ksyms
  1342.         ;;
  1343.     *)
  1344.         KO=ko
  1345.         ksyms=kallsyms
  1346.         ;;
  1347.     esac
  1348.  
  1349.     if uname -v | grep -q SMP; then
  1350.         OSKERNSMP="-SMP"
  1351.     else
  1352.         OSKERNSMP=""
  1353.     fi
  1354.  
  1355.     if [ -r /proc/ksyms ] && [ `egrep -c '_[0-9a-f]{8}$' /proc/ksyms` -gt 100 ]; then
  1356.         OSKERNMODV="-MODVERS"
  1357.     else
  1358.         OSKERNMODV=""
  1359.     fi
  1360.  
  1361.     echo "$OSKERNNAME-$OSKERNARCH($OSKERNTYPE)-$OSKERNVERS$OSKERNSMP$OSKERNMODV $OSDISTNAME-$OSDISTVERS"
  1362. }
  1363.  
  1364. dump_cmd()
  1365. {
  1366.     echo ""
  1367.     echo "${dumpprefix} $*"
  1368.     eval $@
  1369. }
  1370.  
  1371. dump_file()
  1372. {
  1373.     dump_cmd cat -v $@
  1374. }
  1375.  
  1376. dump_diagnostics()
  1377. {
  1378.     dumpprefix="+"
  1379.  
  1380.     > "${cnxtdiagfile}" || return $?
  1381.  
  1382.     if ! ${noprobe}; then
  1383.         echo ""
  1384.         echo "Probing \"/dev/ttySHSF\"..."
  1385.         (
  1386.             dump_cmd modprobe -v /dev/ttySHSF
  1387.             dump_cmd lsmod
  1388.         ) >> "${cnxtdiagfile}" 2>&1
  1389.     fi
  1390.  
  1391.     echo ""
  1392.     echo "Dumping system diagnostic information..."
  1393.  
  1394.     case "${cnxtdiagfile}" in
  1395.     *longdiag*)
  1396.         longdiag=true
  1397.         ;;
  1398.     *)
  1399.         longdiag=false
  1400.         ;;
  1401.     esac
  1402.  
  1403.     (
  1404.         dump_cmd date
  1405.         dump_cmd $0 --info
  1406.         dump_cmd identify_system
  1407.         dump_cmd uname -a
  1408.  
  1409.         dump_cmd gcc -v
  1410.  
  1411.         dump_file /proc/version
  1412.         dump_file /proc/cpuinfo
  1413.  
  1414.         for f in /etc/*_version /etc/*-version /etc/*-release; do
  1415.             if [ -r "${f}" ]; then
  1416.                 dump_file "${f}"
  1417.             fi
  1418.         done
  1419.  
  1420.         for f in /var/run/hsfdcpd*; do
  1421.             if [ -r "${f}" ]; then
  1422.                 dump_file "${f}"
  1423.             fi
  1424.         done
  1425.  
  1426.         dump_cmd lspci -n
  1427.         dump_cmd lspci -v
  1428.         dump_cmd lspci -n -vvv
  1429.  
  1430.         for p in pci cmdline uptime \
  1431.             devices misc filesystems interrupts \
  1432.             iomem ioports dma mtrr \
  1433.             partitions mounts swaps meminfo \
  1434.             stat apm modules ldiscs
  1435.         do
  1436.             dump_file /proc/${p}
  1437.         done
  1438.  
  1439.         dump_cmd modprobe -V
  1440.         dump_cmd modprobe -l "*hsf*"
  1441.         dump_cmd modprobe -l "*hcf*"
  1442.         dump_cmd modprobe -l "*rip*"
  1443.         dump_file "${modulesconf}"
  1444.         if [ -n "${modprobeconf}" ]; then
  1445.             dump_file "${modprobeconf}"
  1446.         fi
  1447.         dump_cmd depmod -e -a
  1448.  
  1449.         dump_file /proc/tty/drivers
  1450.         for f in /proc/tty/driver/*; do
  1451.             if [ -r "${f}" ]; then
  1452.                 dump_file "${f}"
  1453.             fi
  1454.         done
  1455.  
  1456.         dump_cmd ls -l '/dev/modem*'
  1457.         dump_cmd ls -l '/dev/*HSF[0-9]*'
  1458.         dump_cmd ls -l '/dev/ttyS*'
  1459.         dump_cmd ls -l '/dev/tts*'
  1460.  
  1461.         dump_cmd "cd ${cnxtnvmdir} && find . -maxdepth 2 -ls"
  1462.         dump_cmd "cd ${cnxtnvmdir} && find dynamic -follow -print -type f -exec cat {} \;"
  1463.  
  1464.         dump_cmd ls -lR "${cnxtlibdir}/."
  1465.  
  1466.         if ${longdiag}; then
  1467.             for p in slabinfo ${ksyms}
  1468.             do
  1469.                 dump_file /proc/${p}
  1470.             done
  1471.  
  1472.             dump_file /lib/modules/${OSKERNVERS}/build/.config
  1473.             dump_file /lib/modules/${OSKERNVERS}/build/include/linux/version.h
  1474.             dump_file /lib/modules/${OSKERNVERS}/build/include/linux/autoconf.h
  1475.             dump_file /lib/modules/${OSKERNVERS}/build/include/linux/autoconf-up.h
  1476.             dump_file /lib/modules/${OSKERNVERS}/build/include/linux/rhconfig.h
  1477.             dump_file /lib/modules/${OSKERNVERS}/build/include/linux/modules/ksyms.ver
  1478.  
  1479.             dump_file /boot/vmlinuz.version.h
  1480.             dump_file /boot/vmlinuz.autoconf.h
  1481.             dump_file /boot/vmlinuz.config
  1482.  
  1483.             dump_file /boot/kernel.h
  1484.  
  1485.             dump_cmd ls -lR /etc/.
  1486.             dump_cmd ls -lR /lib/modules/.
  1487.             dump_cmd ls -lR /boot/.
  1488.  
  1489.             dump_cmd ls -l /usr/src/linux/include/.
  1490.             dump_cmd ls -l /usr/src/linux/include/linux/.
  1491.             dump_cmd ls -l /usr/src/linux/include/asm-i386/.
  1492.             dump_cmd ls -l /usr/include/. /usr/src/.
  1493.  
  1494.             dump_cmd env
  1495.  
  1496.             dump_cmd ps -efw
  1497.  
  1498.             dump_cmd sh --version
  1499.             dump_cmd sed --version
  1500.             dump_cmd ${AWK} --version
  1501.             dump_cmd printf --version
  1502.  
  1503.             dump_cmd tar --version
  1504.  
  1505.             dump_cmd rpm --version
  1506.             dump_cmd rpm --showrc
  1507.             dump_cmd rpm --query --all
  1508.         fi
  1509.  
  1510.         dump_cmd dmesg
  1511.         if dmesg | grep -qi 'panic'; then
  1512.             dump_cmd dmesg | ksymoops
  1513.         fi
  1514.  
  1515.     ) >> "${cnxtdiagfile}" 2>&1
  1516.  
  1517.     if [ -f "${cnxtdiagfile}" ]; then
  1518.         echo ""
  1519.         echo "System diagnostic information has been saved to the file:"
  1520.         echo ""
  1521.         ls -l ${cnxtdiagfile}
  1522.         echo ""
  1523.         echo "As it could contain private information about this system, we recommend that"
  1524.         echo "you verify its contents before sending it to third parties."
  1525.     fi
  1526. }
  1527.  
  1528. read_unit_parms()
  1529. {
  1530.     parm_regionName[${unit}]="AUTO"
  1531.     parm_regionT35c[${unit}]=""
  1532.     parm_hwprofile[${unit}]="unknown"
  1533.     parm_hwrevision[${unit}]=""
  1534.     parm_hwinst[${unit}]="none"
  1535.     parm_hwid[${unit}]="unknown"
  1536.     parm_licowner[${unit}]="${lastowner}"
  1537.     parm_lickey[${unit}]="00000000"
  1538.     parm_licstatus[${unit}]="unknown"
  1539.  
  1540.     if [ ! -d "${procdrvdir}/${unit}" ]; then
  1541.         echo ""
  1542.         echo 1>&2 "ERROR: no modem found (unit ${unit})"
  1543.         return 1
  1544.     fi
  1545.  
  1546.     read parm_hwprofile[${unit}] < ${procdrvdir}/${unit}/hwprofile
  1547.     read parm_hwrevision[${unit}] < ${procdrvdir}/${unit}/hwrevision
  1548.     read parm_hwinst[${unit}] < ${procdrvdir}/${unit}/hwinst
  1549.  
  1550.     if [ ! -d "${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}" ]; then
  1551.         echo ""
  1552.         echo 1>&2 "ERROR: hwinst dir not present: ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}"
  1553.         return 2
  1554.     fi
  1555.  
  1556.  
  1557.     if [ -f ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/.region_set ]; then
  1558.         read parm_regionT35c[${unit}] < ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/COUNTRY_CODE
  1559.         parm_regionName[${unit}]="`T35c_to_name \"${parm_regionT35c[${unit}]}\"`"
  1560.     fi
  1561.  
  1562.     if ${isfreeversion}; then
  1563.         sawfreelicenses=true
  1564.     else
  1565.         read hwid < ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/HARDWARE_ID
  1566.         sum="`echo \"${hwid}\" | md5sum | cut -c1-4 | tr '[a-f]' '[A-F]'`"
  1567.         parm_hwid[${unit}]="${sum}-`echo \"${hwid}\" | sed 's/^\(....\)\(....\)$/\1-\2/'`"
  1568.  
  1569.         [ -s ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_OWNER ] &&
  1570.             parm_licowner[${unit}]="`sed 's/"//g' < ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_OWNER`"
  1571.         [ -n "${parm_licowner[${unit}]}" -a "${parm_licowner[${unit}]}" != "unknown" ] && lastowner="${parm_licowner[${unit}]}"
  1572.  
  1573.         [ -s ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_KEY ] &&
  1574.             read parm_lickey[${unit}] < ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_KEY
  1575.  
  1576.         [ -s ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_STATUS ] &&
  1577.             parm_licstatus[${unit}]="`sed 's/"//g' < ${cnxtnvmdir}/dynamic/${parm_hwinst[${unit}]}/LICENSE_STATUS`"
  1578.         case "${parm_licstatus[${unit}]}" in
  1579.         FREE*)
  1580.             sawfreelicenses=true
  1581.             ;;
  1582.         *)
  1583.             ;;
  1584.         esac
  1585.     fi
  1586.  
  1587.     return 0
  1588. }
  1589.  
  1590. ensure_driver_present()
  1591. {
  1592.     if [ ! -d ${procdrvdir} ]; then
  1593.         modprobe /dev/ttySHSF >/dev/null 2>&1 # ensure drv loaded
  1594.         if [ ! -d ${procdrvdir} ]; then
  1595.             echo ""
  1596.             echo 1>&2 "ERROR: hsf driver not active"
  1597.             return 1
  1598.         fi
  1599.     fi
  1600.     return 0
  1601. }
  1602.  
  1603. read_parms()
  1604. {
  1605.     sawfreelicenses=false
  1606.     
  1607.     ensure_driver_present || return $?
  1608.     units="${specificunit}"
  1609.     if [ -z "${units}" ]; then
  1610.         units=`ls ${procdrvdir}`
  1611.  
  1612.         if [ -z "${units}" ]; then
  1613.             echo ""
  1614.             echo 1>&2 "ERROR: no device detected by hsf driver"
  1615.             return 1
  1616.         fi
  1617.     fi
  1618.  
  1619.     for unit in ${units}; do
  1620.         read_unit_parms || return $?
  1621.     done
  1622.     rereadparms=false
  1623. }
  1624.  
  1625. show_unit_parms()
  1626. {
  1627.     echo ""
  1628.     echo "Config for modem unit ${unit}: /dev/ttySHSF${unit}"
  1629.     echo "    Device instance: ${parm_hwinst[${unit}]}"
  1630.     if [ -n "${parm_hwrevision[${unit}]}" ]; then
  1631.         echo "    HW revision    : ${parm_hwrevision[${unit}]}"
  1632.     fi
  1633.     echo "    HW profile name: ${parm_hwprofile[${unit}]}"
  1634.     if ! ${isfreeversion}; then
  1635.         echo "    Registration ID: ${parm_hwid[${unit}]}"
  1636.         echo "    License owner  : ${parm_licowner[${unit}]}"
  1637.         echo "    License key    : `keytodisp \"${parm_lickey[${unit}]}\"`"
  1638.         echo "    License status : ${parm_licstatus[${unit}]}"
  1639.     fi
  1640.     if [ -n "${parm_regionT35c[${unit}]}" ]; then
  1641.         echo "    Current region : ${parm_regionName[${unit}]} (T.35 code: ${parm_regionT35c[${unit}]})"
  1642.     else
  1643.         echo "    Current region : ${parm_regionName[${unit}]}"
  1644.     fi
  1645. }
  1646.  
  1647. show_intro()
  1648. {
  1649.     echo "Conexant HSF softmodem driver, version ${cnxtversion}"
  1650.  
  1651.     case "${cnxtversion}" in
  1652.     *beta*)
  1653.         (
  1654.         echo ""
  1655.         echo "WARNING: this is an EXPERIMENTAL BETA VERSION"
  1656.         echo "USE AT YOUR OWN RISK! See the file ${cnxtlibdir}/LICENSE for details."
  1657.         ) 1>&2
  1658.         ;;
  1659.     esac
  1660.  
  1661. #    case "${cnxtversion}" in
  1662. #    *lnxt*)
  1663.         (
  1664.         echo ""
  1665.         echo "If you need license keys, assistance or more information, please go to:"
  1666.         echo "    http://www.linuxant.com/"
  1667.         echo ""
  1668.         echo "When reporting a problem for the first time, please send"
  1669.         echo "us the file generated by \"hsfconfig --dumpdiag\"."
  1670.         ) 1>&2
  1671. #        ;;
  1672. #    esac
  1673. }
  1674.  
  1675.  
  1676. show_usage_and_exit()
  1677. {
  1678.     show_intro
  1679.  
  1680.     cat 1>&2 << EOT
  1681.  
  1682. Usage: `basename $0` [options]
  1683.  
  1684.   -u, --unit=<number>          Select modem unit (default 0)
  1685.   -c, --region[=<name>]        Set region, to <name> if specified
  1686.                                (Use name "AUTO" to infer from timezone)
  1687.   -k, --kernel                 Build and install kernel modules
  1688.   -s, --serial                 Install serial port devices
  1689.  
  1690.   -i, --info                   Show current configuration information
  1691.  
  1692.   -l, --license[=<owner/key>]  Set license key
  1693.  
  1694.   -P, --hwprofile[=<name>]     Set HW profile name, to <name> if specified
  1695.  
  1696.   -d, --dumpdiag[=<file>]      Probe driver modules and dump system diagnostic
  1697.                                information to <file>
  1698.                                (default: ${cnxtdiagfile})
  1699.  
  1700.   -N, --noprobe                Do dumpdiag without probing modules (safer)
  1701.  
  1702.   -a, --auto                   Run in automatic mode, without prompting user
  1703.   -r, --remove                 Remove serial devices and kernel modules
  1704.  
  1705.   -h, --help                   This small usage guide
  1706.   -V, --version                Show version
  1707.  
  1708. Default options if none selected: --kernel --serial --region --license --info
  1709. EOT
  1710.     exit 1
  1711. }
  1712.  
  1713. # end of functions; execution starts here
  1714.  
  1715. PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin
  1716. export PATH
  1717.  
  1718. umask 022
  1719.  
  1720. cnxtlibdir="/usr/lib/hsfmodem"
  1721. cnxtetcdir="/etc/hsfmodem"
  1722. cnxtnvmdir="/etc/hsfmodem/nvm"
  1723. cnxtinfdir="/tmp/no/longer/used"
  1724. cnxtinffil="/tmp/no/longer/used"
  1725. cnxtversion="6.03.00lnxt03091800free"
  1726.  
  1727. case "${cnxtversion}" in
  1728. *free*)
  1729.     isfreeversion=true
  1730.     ;;
  1731. *)
  1732.     isfreeversion=false
  1733.     ;;
  1734. esac
  1735.  
  1736. cnxtdiagfile="/tmp/hsfdiag.txt"
  1737.  
  1738. if [ -f /etc/modules.conf ]; then
  1739.     modulesconf=/etc/modules.conf
  1740. elif [ -f /etc/conf.modules ]; then
  1741.     modulesconf=/etc/conf.modules
  1742. else
  1743.     # create /etc/modules.conf if it doesn't exist
  1744.     modulesconf=/etc/modules.conf
  1745.     touch ${modulesconf}
  1746. fi
  1747.  
  1748. if [ -f /etc/modprobe.conf ]; then
  1749.     modprobeconf=/etc/modprobe.conf
  1750. elif which generate-modprobe.conf >/dev/null 2>&1; then
  1751.     modprobeconf=/etc/modprobe.conf
  1752.     # create /etc/modprobe.conf if it doesn't exist
  1753.     touch ${modprobeconf}
  1754. fi
  1755.  
  1756. TEMP=`getopt -a -o u::c::C::ksil::P::d::NarhV --long unit::,region::,country::,kernel,serial,info,license::,hwprofile::,dumpdiag::,noprobe,auto,remove,help,version -n "\`basename $0\`" -- "$@"`
  1757. if [ $? != 0 ]; then
  1758.     show_usage_and_exit
  1759. fi
  1760.  
  1761. eval set -- "$TEMP"
  1762.  
  1763. automode=false
  1764. noprobe=false
  1765. do_cfgkernel=false
  1766. do_cfgserial=false
  1767. do_cfglicense=false
  1768. do_cfghwprofile=false
  1769. do_infocfg=false
  1770. do_dumpdiag=false
  1771. do_cfgremove=false
  1772. do_cfgregion=false
  1773. setregion=""
  1774. setlicense=""
  1775. setlicowner=""
  1776. sethwprofile=""
  1777. setdiagfile=""
  1778. specificunit=""
  1779. lastowner="unknown"
  1780.  
  1781. if which gawk >/dev/null 2>&1; then
  1782.     AWK=gawk
  1783. else
  1784.     AWK=awk
  1785. fi
  1786.  
  1787. explicitopt=false
  1788.  
  1789. while true ; do
  1790.     case "$1" in
  1791.         -a|--auto) automode=true; shift ;;
  1792.         -c|--region|-C|--country)
  1793.             explicitopt=true
  1794.             do_cfgregion=true
  1795.             if [ -n "$2" ]; then
  1796.                 setregion="`echo \"$2\" | tr '[a-z ]' '[A-Z_]'`"
  1797.             fi
  1798.             shift 2
  1799.             ;;
  1800.         -u|--unit)
  1801.             explicitopt=true
  1802.             specificunit="$2"
  1803.             shift 2
  1804.             ;;
  1805.         -k|--kernel) explicitopt=true; do_cfgkernel=true; shift ;;
  1806.         -s|--serial) explicitopt=true; do_cfgserial=true; shift ;;
  1807.         -l|--license)
  1808.             explicitopt=true
  1809.             do_cfglicense=true
  1810.             if [ -n "$2" ]; then
  1811.                 setlicense="$2"
  1812.             fi
  1813.             shift 2
  1814.             ;;
  1815.         -P|--hwprofile)
  1816.             explicitopt=true
  1817.             do_cfghwprofile=true
  1818.             if [ -n "$2" ]; then
  1819.                 sethwprofile="$2"
  1820.             fi
  1821.             shift 2
  1822.             ;;
  1823.         -i|--info)   explicitopt=true; do_infocfg=true; shift ;;
  1824.         -d|--dumpdiag)
  1825.             explicitopt=true
  1826.             do_dumpdiag=true
  1827.             setdiagfile="$2"
  1828.             shift 2
  1829.             ;;
  1830.         -N|--noprobe)
  1831.             explicitopt=true
  1832.             do_dumpdiag=true
  1833.             noprobe=true
  1834.             shift
  1835.             ;;
  1836.         -r|--remove) explicitopt=true; do_cfgremove=true; shift ;;
  1837.         -h|--help) show_usage_and_exit; shift ;;
  1838.         -V|--version) echo "${cnxtversion}"; exit 0;;
  1839.         --) shift ; break ;;
  1840.         *) echo "Internal error!" ; exit 1 ;;
  1841.     esac
  1842. done
  1843.  
  1844. # Accept --region <name> as equivalent to --region=<name>
  1845. if ${do_cfgregion} && [ $# -ge 1 -a -z "${setregion}" ]; then
  1846.     setregion="`echo \"$1\" | tr '[a-z ]' '[A-Z_]'`"
  1847.     shift
  1848. fi
  1849.  
  1850. # Accept --license <name> as equivalent to --license=<name>
  1851. if ${do_cfglicense} && [ $# -ge 1 -a -z "${setlicense}" ]; then
  1852.     setlicense="$1"
  1853.     shift
  1854. fi
  1855.  
  1856. # Accept --hwprofile <name> as equivalent to --hwprofile=<name>
  1857. if ${do_cfghwprofile} && [ $# -ge 1 -a -z "${sethwprofile}" ]; then
  1858.     sethwprofile="$1"
  1859.     shift
  1860. fi
  1861.  
  1862. # Accept --dumpdiag <file> as equivalent to --dumpdiag=<file>
  1863. if ${do_dumpdiag} && [ $# -ge 1 -a -z "${setdiagfile}" ]; then
  1864.     setdiagfile="$1"
  1865.     shift
  1866. fi
  1867.  
  1868. procdrvdir="/proc/driver/hsf"
  1869.  
  1870. if [ $# -ne 0 ]; then
  1871.     echo 1>&2 "$0: extraneous arguments: $*"
  1872.     show_usage_and_exit
  1873. fi
  1874.  
  1875. # If nothing explicitely specified, configure everything
  1876. if ! ${explicitopt}; then
  1877.     do_cfgkernel=true
  1878.     do_cfgserial=true
  1879.     do_cfgregion=true
  1880.     if ! ${isfreeversion}; then
  1881.         do_cfglicense=true
  1882.     fi
  1883.     do_infocfg=true
  1884. fi
  1885.  
  1886. if ! ${do_cfgremove}; then
  1887.     show_intro
  1888. fi
  1889.  
  1890. identify_system >/dev/null
  1891.  
  1892. if ${do_cfgremove}; then
  1893.     remove_kernel_modules || exit $?
  1894.     hsfstop
  1895.     unconfigure_serial || exit $?
  1896.     rm -rf "${cnxtnvmdir}/dynamic"
  1897. fi
  1898.  
  1899. if ${do_cfgkernel}; then
  1900.     configure_kernel || exit $?
  1901. fi
  1902.  
  1903. if ${do_cfgserial}; then
  1904.     configure_serial || exit $?
  1905. fi
  1906.  
  1907. rereadparms=true
  1908. if ${do_cfgregion} || ${do_cfglicense} || ${do_cfghwprofile}; then
  1909.     read_parms || exit $?
  1910. fi
  1911.  
  1912. if ${do_cfgregion}; then
  1913.     for unit in ${units}; do
  1914.         configure_region || exit $?
  1915.     done
  1916.     echo ""
  1917.     echo "To change, use \"hsfconfig --region\" or \"AT+GCI=<T35code>\""
  1918.     echo "The current region can be displayed by entering \"ATI9\" in a terminal program."
  1919. fi
  1920.  
  1921. if ${do_cfglicense}; then
  1922.     for unit in ${units}; do
  1923.         configure_license
  1924.         res=$?
  1925.         if [ ${res} -ne 0 ] && ${explicitopt}; then
  1926.             exit ${res}
  1927.         fi
  1928.     done
  1929.     do_infocfg=true
  1930. fi
  1931.  
  1932. if ${do_cfghwprofile}; then
  1933.     for unit in ${units}; do
  1934.         configure_hwprofile || exit $?
  1935.     done
  1936.     do_infocfg=true
  1937. fi
  1938.  
  1939. if ${do_infocfg}; then
  1940.     if ${rereadparms}; then
  1941.         read_parms || exit $?
  1942.     fi
  1943.     echo ""
  1944.     echo "Current parameters: (\"hsfconfig --info\")"
  1945.     for unit in ${units}; do
  1946.         show_unit_parms
  1947.     done
  1948.     if [ -h /dev/modem ]; then
  1949.         echo ""
  1950.         echo "The /dev/modem alias (symlink) points to `/bin/ls -l /dev/modem 2>/dev/null | ${AWK} '{print $11}'`"
  1951.     fi
  1952.     if ${sawfreelicenses}; then
  1953.         if ${isfreeversion}; then
  1954.             needfullversion
  1955.         else
  1956.             echo ""
  1957.             echo "To enable full 56K modem and FAX functionality, enter your license information"
  1958.             echo "with \"hsfconfig --license\"."
  1959.             echo ""
  1960.             echo "License owner and key data must EXACTLY match the information respectively"
  1961.             echo "provided to and by Linuxant. Otherwise, license status will remain \"FREE\"!"
  1962.         fi
  1963.     fi
  1964. fi
  1965.  
  1966. if ${do_dumpdiag}; then
  1967.     if [ -n "${setdiagfile}" ]; then
  1968.         cnxtdiagfile="${setdiagfile}"
  1969.     fi
  1970.     dump_diagnostics || exit $?
  1971. fi
  1972.  
  1973.